<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>客户管理</title>
<%@ include file="head.jsp" %>
</head>
<body>
<div class="easyui-panel" data-options="title:'查询',width:'100%',height:100,collapsible:true">
    <form id="customer_search_form" action="">
        <table class="searchTb">
            <tr>
                <th>客户名称：</th>
                <td><input type="text" id="customname" name="customname" /> </td>
                <td>
                    &nbsp;<a href="javascript:search_customer();" class="easyui-linkbutton m10" title="查询" data-options="iconCls:'icon-search'">查询</a>
                </td>
            </tr>
        </table>
    </form>
</div>
<table id="customer_dg"></table>
<div id="formbox"></div>
<script type="text/javascript" src="static/js/customer_manage.js"></script>
<script type="text/javascript">
	$(function() {
		$("#customer_dg")
				.datagrid(
						{
							url : "customer/list",
							columns : [ [
									{
										field : 'customname',
										title : '客户名称'
									},
									{
										field : 'bossname',
										title : '法人代表'
									},
									{
										field : 'regdatetime',
										title : '注册时间',
										formatter :  function(value) {
			                        		if(value==null)
			                        			return;
			                                var date = new Date(value);
			                                var year = date.getFullYear().toString();
			                                var month = (date.getMonth() + 1);
			                                var day = date.getDate().toString();
			                                return year + "-" + month + "-" + day;
										}
									},
									{field:'customtypename',title:'类型'},
									{
										field : 'customstatus',
										title : '状态',
										align : 'center',
										formatter : function(value, row, index) {
											//formatter  表格格式化函数，返回3个参数：字段值，该行数据，该行索引
											switch (value) {
											case 0:
												return "停用";
												break;
											case 1:
												return "启用";
												break;
											default:
												return "-";
												break;
											}
										},
										styler : function(value, row, index) {
											if (value == 0) {
												return 'color:red;';
											}else{
												return 'color:green;';
											}
										}
									},
									{title:'操作',field:'id',
										formatter : function(value, row, index) {
											var status = row.customstatus;
											var customName = row.customname;
											switch (status) {
											case 1:
												return '<a href="javascript:viewCustom('+value+');"  class="easyui-linkbutton">查看</a>  <a href="javascript:updateCustom('+value+');" class="easyui-linkbutton">修改</a>  <a href="javascript:updateCustomerStatus('+value+','+status+',\''+customName+'\');" style="color:red;" class="easyui-linkbutton">停用</a>';
												break;
											case 0:
												return '<a href="javascript:viewCustom('+value+');" class="easyui-linkbutton">查看</a>  <a href="javascript:updateCustom('+value+');" class="easyui-linkbutton">修改</a>  <a href="javascript:updateCustomerStatus('+value+','+status+',\''+customName+'\');" style="color:green;" class="easyui-linkbutton">启用</a>';
												break;
											default:
												return "-";
												break;
											}
										}								
									}] ],
							toolbar : [ {
								text : '新增',
								iconCls : 'icon-add',
								handler : addCustomer
							}],
							fitColumns : true,//自适应宽度 
							striped : true,//列表是否有间隔底色
							resizable : true,//列尺寸可调节
							singleSelect : true,
							loadMsg : '正在努力加载中..',
							rownumbers : true, //行前显示行号
							idField : 'id', //指定选中时返回的维度字段名，如id

							pagination : true,//是否显示分页
							pageSize : 10,//每页条数 
							pageList : [ 10,20,30 ]
						});
	});
	
	//新增函数
	function addCustomer() {
		/* //获取当前iframe
		var curTab = parent.$('#mainTabs').tabs('getSelected');
		//alert(curTab);
		curTab.find('iframe')[0].src='customer/add'; */
    	$('#formbox').dialog({
			title : '添加客户',
			height: '600',
			width:'100%',
			closed : false,
			cache : false,
			href : 'customer/add',
			modal : true,
			buttons:[{
				text:'添  加',
				handler:function(){
					saveCustomer();
				}
			},{
				text:'取  消',
				handler:function(){
					$('#formbox').dialog('close');
				}
			}]
		});
	}
	//修改函数
	function updateCustom(id) {
    	$('#formbox').dialog({
			title : '修改客户',
			height: 600,
			width:'100%',
			closed : false,
			cache : false,
			href : 'customer/update?id='+id,
			modal : true,
			buttons:[{
				text:'修  改',
				handler:function(){
					updateCustomer();
				}
			},{
				text:'取  消',
				handler:function(){
					$('#formbox').dialog('close');
				}
			}]
		});
	}
//搜索方法
function search_customer(){
	var customer = {customname:$.trim($('#customname').val())};
	$('#customer_dg').datagrid('options').queryParams = customer;  	   
    $("#customer_dg").datagrid('reload');  
}
</script>
</body>
</html>